Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verilog preprocessor: implement multi-line defines #77

Merged
merged 1 commit into from
Sep 26, 2023

Conversation

kroening
Copy link
Member

This implements multi-line macros in the Verilog preprocessor.

This implements multi-line macros in the Verilog preprocessor.
@@ -362,13 +362,23 @@ void verilog_preprocessort::directive()
// skip whitespace
tokenizer().skip_ws();

// Read any tokens until end of line.
// Read any tokens until end of line,
// but note that \n can be escaped with a backslash.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't verilog_preprocessor_token_sourcet::skip_until_eol also learn about this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately the standard is very unclear under which circumstances this is supposed to happen. I'll need to experiment with some standard tools.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is global, it might be preferable to move the escaping into the flex tokenizer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +377 to +381
auto nl = tokenizer().next_token();
define.tokens.push_back(std::move(nl));
}
else
define.tokens.push_back(std::move(token));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a matter of taste:

...
  token = tokenizer().next_token();
}
define.tokens.push_back(std::move(token));

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed a matter of taste; I do feel that the longer version is quicker to understand.

@tautschnig
Copy link
Collaborator

Also, are we still getting line numbers right in any warnings/errors affecting lines after a multi-line define?

@kroening kroening merged commit c20afa1 into main Sep 26, 2023
@kroening
Copy link
Member Author

Also, are we still getting line numbers right in any warnings/errors affecting lines after a multi-line define?

Yes, the line counting happens in the tokenizer.

@kroening kroening deleted the multi-line-define branch September 26, 2023 15:36
@kroening
Copy link
Member Author

e?

Right instinct; while the line counting in the preprocessor works, the line counting in the parser is off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants